CREATE OR REPLACE FUNCTION ifnull(val1 ANYELEMENT, val2 ANYELEMENT)
RETURNS ANYELEMENT
AS
$$
BEGIN
    IF val1 IS NULL THEN
        RETURN val2;
ELSE
        RETURN val1;
END IF;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION sysdate()
RETURNS TIMESTAMP WITH TIME ZONE
AS
$$
BEGIN
RETURN now();
END;
$$ LANGUAGE plpgsql;